home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Computer Select (Limited Edition)
/
Computer Select.iso
/
pcmag
/
v11n07
/
demo_6.exe
/
DE6SRC.EXE
/
DEMO6.C
< prev
next >
Wrap
Text File
|
1992-02-08
|
16KB
|
380 lines
// DEMO6.C --- Pen-centric Windows application that demonstrates
// handwritten input using the Recognize() function.
// Copyright (C) 1992 Ray Duncan
#define WIN31
#define dim(x) (sizeof(x) / sizeof(x[0])) // returns no. of elements
#define BUFMAX 80 // size of scratch buffers
#include "windows.h"
#include "penwin.h"
#include "demo6.h"
HANDLE hInst; // instance handle
HWND hWndFrame = 0; // frame window handle
HWND hWndText = 0; // child text window handle
HWND hWndWrite = 0; // child writing window handle
HANDLE hPenWin = 0; // Pen Windows module handle
int CharX = 0; // average char width
int CharY = 0; // char height
int CurLine = 0; // current line number
int MaxLine = 0; // maximum line number
int EnumCount = 0; // translation counter
char szFrameClass[] = "DemoFrameClass"; // name of frame window class
char szTextClass[] = "DemoTextClass"; // child text window class
char szWriteClass[] = "DemoWriteClass"; // child writing window class
struct { // result codes returned
int Code; // by Recognize() function
char * Name;
} recogResults[] = {
REC_OK, "REC_OK",
REC_ABORT, "REC_ABORT",
REC_BADHPENDATA, "REC_BADHPENDATA",
REC_BUFFERTOOSMALL, "REC_BUFFERTOOSMALL",
REC_BUSY, "REC_BUSY",
REC_DONE, "REC_DONE",
REC_NOINPUT, "REC_NOINPUT",
REC_NOTABLET, "REC_NOTABLET",
REC_OOM, "REC_OOM",
REC_OVERFLOW, "REC_OVERFLOW",
REC_TERMBOUND, "REC_TERMBOUND",
REC_TERMEX, "REC_TERMEX",
REC_TERMOEM, "REC_TERMOEM",
REC_TERMPENUP, "REC_TERMPENUP",
REC_TERMRANGE, "REC_TERMRANGE",
REC_TERMTIMEOUT, "REC_TERMTIMEOUT", } ;
struct { // result types returned
int Code; // in RCRESULT structure
char * Name;
} rctypeResults[] = {
RCRT_UNIDENTIFIED, "RCRT_UNIDENTIFIED",
RCRT_GESTURE, "RCRT_GESTURE",
RCRT_NOSYMBOLMATCH, "RCRT_NOSYMBOLMATCH",
RCRT_PRIVATE, "RCRT_PRIVATE",
RCRT_NORECOG, "RCRT_NORECOG",
RCRT_ALREADYPROCESSED, "RCRT_ALREADYPROCESSED",
RCRT_GESTURETRANSLATED, "RCRT_GESTURETRANSLATED",
RCRT_GESTURETOKEYS, "RCRT_GESTURETOKEYS", } ;
//
// WinMain --- entry point from Windows. Registers window classes,
// creates windows, registers pen app, and processes messages until
// WM_QUIT received.
//
int PASCAL WinMain(HANDLE hInstance,
HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
hInst = hInstance; // save this instance handle
if(!hPrevInstance) // if first instance,
if(!InitApplication(hInstance)) // register window class
return(FALSE); // exit if couldn't register
if(!InitInstance(hInstance, nCmdShow)) // create this instance's window
{
MessageBox(0, "Initialization failed!", "DEMO6", MB_OK|MB_ICONSTOP);
return(FALSE);
}
RegisterPenApp(RPA_DEFAULT, TRUE); // enable HEDIT/BEDIT controls
while(GetMessage(&msg, NULL, 0, 0)) // while message != WM_QUIT
{
TranslateMessage(&msg); // translate virtual key codes
DispatchMessage(&msg); // dispatch message to window
}
return(msg.wParam); // return code = WM_QUIT value
}
//
// InitApplication --- registers window classes for this application
//
BOOL InitApplication(HANDLE hInstance)
{
WNDCLASS wc;
BOOL bParent;
BOOL bText;
BOOL bWrite;
// set parameters for frame window class
wc.style = CS_HREDRAW | CS_VREDRAW; // class style
wc.lpfnWndProc = FrameWndProc; // class callback function
wc.cbClsExtra = 0; // extra per-class data
wc.cbWndExtra = 0; // extra per-window data
wc.hInstance = hInstance; // handle of class owner
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // default cursor
wc.hbrBackground = GetStockObject(WHITE_BRUSH); // background color
wc.lpszMenuName = "DemoMenu"; // name of menu resource
wc.lpszClassName = szFrameClass; // name of window class
bParent = RegisterClass(&wc); // register frame window class
// set parameters for text output child window class
wc.lpfnWndProc = TextWndProc; // class callback function
wc.hIcon = NULL; // default icon
wc.lpszMenuName = NULL; // name of menu resource
wc.lpszClassName = szTextClass; // name of window class
bText = RegisterClass(&wc); // register text child class
// set parameters for writing input child window class
wc.lpfnWndProc = WriteWndProc; // class callback function
wc.lpszClassName = szWriteClass; // name of window class
bWrite = RegisterClass(&wc); // register writing child class
return(bParent && bText && bWrite); // return success/failure flag
}
//
// InitInstance --- creates frame window for this application instance
//
BOOL InitInstance(HANDLE hInstance, int nCmdShow)
{
hWndFrame = CreateWindow( // create frame window
szFrameClass, // window class name
"Pen Windows Demo #6", // text for title bar
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, CW_USEDEFAULT, // default position
CW_USEDEFAULT, CW_USEDEFAULT, // default size
NULL, // no parent window
NULL, // use class default menu
hInstance, // window owner
NULL // unused pointer
);
if(!hWndFrame) return(FALSE); // error, can't create window
ShowWindow(hWndFrame, nCmdShow); // make frame window visible
UpdateWindow(hWndFrame); // force WM_PAINT message
return(TRUE); // return success flag
}
//
// FrameWndProc --- callback function for application frame window
//
long FAR PASCAL FrameWndProc(HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
switch (wMsg)
{
case WM_CREATE: // creating frame window
hWndText = CreateWindow( // create child text window
szTextClass, // window class name
NULL, // text for title bar
WS_CHILDWINDOW | WS_VISIBLE | WS_BORDER, // style
0, 0, 0, 0, // position and size
hWnd, // frame window is parent
0, // child window identifier
hInst, // window owner
NULL); // unused pointer
hWndWrite = CreateWindow( // create child writing window
szWriteClass, // window class name
NULL, // text for title bar
WS_CHILDWINDOW | WS_VISIBLE | WS_BORDER, // style
0, 0, 0, 0, // position and size
hWnd, // frame window is parent
0, // child window identifier
hInst, // window owner
NULL); // unused pointer
break;
case WM_SIZE: // resize